CREATE TABLE [dbo].[tb_Reparticiones]
(
[idReparticion] [int] NOT NULL IDENTITY(1, 1),
[Reparticion] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Descripcion] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[EsEscuela] [varchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Organizacion] [int] NULL,
[IdTipoReparticion] [int] NOT NULL CONSTRAINT [DF_tb_Reparticiones_IdTipoReparticion] DEFAULT ((1))
) ON [PRIMARY]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TRIGGER [dbo].[delete_Reparticiones] ON [dbo].[tb_Reparticiones]
FOR DELETE 
AS
 DELETE tb_Usuarios FROM tb_Usuarios WHERE idReparticion in (SELECT idReparticion FROM deleted)
GO
ALTER TABLE [dbo].[tb_Reparticiones] ADD CONSTRAINT [PK_tb_Reparticiones] PRIMARY KEY CLUSTERED  ([idReparticion]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [idxOrganizacionReparticiones] ON [dbo].[tb_Reparticiones] ([Organizacion]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[tb_Reparticiones] ADD CONSTRAINT [FK_tb_Reparticiones_Tb_TiposDeReparticion] FOREIGN KEY ([IdTipoReparticion]) REFERENCES [dbo].[Tb_TiposDeReparticion] ([IDTipoReparticion])
GO
ALTER TABLE [dbo].[tb_Reparticiones] WITH NOCHECK ADD CONSTRAINT [FK_tb_Reparticiones_tb_Organizaciones] FOREIGN KEY ([Organizacion]) REFERENCES [dbo].[tb_Organizaciones] ([idOrganizaciones])
GO
